<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by CodeTlan.
 * User: Ing. Miguel Salas
 * Date: 3/4/12
 * Time: 9:28 PM
 */
class Delegados extends CT_Controller
{
    function __construct(){
        parent::__construct();
        $this->load->model("delegado", "dao");
    }
    function add(){
        $result=$this->dao->find('delegado_k',array('ficha'=>$this->input->post("ficha")),0,1);
        if($result["total"]==0){
            $data["ficha"]=$this->input->post("ficha");
            $data["nombre"]=$this->input->post("nombre");
            $data["apellidos"]=$this->input->post("apellidos");
            $data["activo"]=1;
            $data["estatus"]=1;
            echo $this->_add($data);
        }
        else echo "{success:false}";
    }
    function edit(){
        $data=(array) json_decode($this->input->post("mod"));
        echo $this->_edit($data,array('delegado_k' => $this->input->post('delegado_k')));
    }
    function active()
    {
        echo $this->_edit(array('activo' => $this->input->post('activo')), array('delegado_k' => $this->input->post('delegado_k')));

    }
    function delete()
    {
        echo $this->_edit(array("estatus" => 0), array('delegado_k' => $this->input->post('delegado_k')));
    }
    function find(){
        $result=$this->dao->find("
        delegado_k,
        ficha,
        nombre,
        apellidos,
        concat_ws(' ',nombre, apellidos) as delegado,
        activo
        ",'',$this->input->post("start"),NUM_ROWS);
        echo $this->getSuccess($result);
    }
}
